package logic

import (
	"context"
	"house_srv/house_srv"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateHouseLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCreateHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateHouseLogic {
	return &CreateHouseLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CreateHouseLogic) CreateHouse(req *types.CreateHouseRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	house, err := l.svcCtx.HouseSrv.CreateHouse(l.ctx, &house_srv.CreateHouseRequest{
		Name:    req.Name,
		Price:   float32(req.Price),
		Address: req.Address,
		Hav:     req.Hav,
		Img:     req.Img,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "成功",
		Code:    200,
		Data:    house,
	}, nil
}
